package com.example;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.ibatis.datasource.DataSourceFactory;

import javax.sql.DataSource;
import java.util.Properties;

public class DBCPDataSourceFactory implements DataSourceFactory {
    private BasicDataSource dataSource;

    @Override
    public void setProperties(Properties props) {
        dataSource = new BasicDataSource();
        dataSource.setDriverClassName(props.getProperty("driver"));
        dataSource.setUrl(props.getProperty("url"));
        dataSource.setUsername(props.getProperty("username"));
        dataSource.setPassword(props.getProperty("password"));
        dataSource.setMaxActive(Integer.parseInt(props.getProperty("maxActive")));
        dataSource.setMaxIdle(Integer.parseInt(props.getProperty("maxIdle")));
        dataSource.setMaxWait(Long.parseLong(props.getProperty("maxWait")));
    }

    @Override
    public DataSource getDataSource() {
        return dataSource;
    }
}